import 'package:flutter/material.dart';
import 'package:flutter_app/openeye/widget/app_bar.dart';

class PartNavigator extends StatefulWidget {
  const PartNavigator({Key? key}) : super(key: key);

  @override
  _PartNavigatorState createState() => _PartNavigatorState();
}

class _PartNavigatorState extends State<PartNavigator> {
  @override
  Widget build(BuildContext context) {
    return materialPage(appBar: appBar("部分页面切换测试"), page: createPartNav());
  }

  createPartNav() {
    return Container(
      height: 350,
      width: 350,
      color: Colors.blueGrey,
      padding: const EdgeInsets.all(10),
      child: Navigator(
        initialRoute: "/",
        onGenerateRoute: (settings) {
          WidgetBuilder builder = (context) => const PartPage();
          switch (settings.name) {
            case '/':
              builder = (context) => const PartPage();
              break;
          }
          return MaterialPageRoute(builder: builder);
        },
      ),
    );
  }
}

class PartPage extends StatelessWidget {
  const PartPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const PageA(
      isShowBackButton: true,
      isShowNext: true,
      pageIndex: 0,
    );
  }
}

class PageA extends StatelessWidget {
  const PageA(
      {Key? key,
      required this.isShowBackButton,
      required this.isShowNext,
        required this.pageIndex})
      : super(key: key);
  final bool isShowBackButton;
  final bool isShowNext;
  final int pageIndex;
  @override
  Widget build(BuildContext context) {
    return materialPage(
        appBar: appBar("内部导航栏",
            backButton: _judeBackButton(), actions: _judeNextButton(context)),
        page: createPartPage(context));
  }

  createPartPage(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      child: Text("当前是第:$pageIndex个页面"),
    );
  }

  _judeBackButton() =>
      isShowBackButton ? const BackButton(color: Colors.black) : null;

  _judeNextButton(BuildContext context) {
        return isShowNext
        ? [InkWell(
            child: const Icon(Icons.navigate_next, color: Colors.black),
            onTap: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (context) {
                return PageA(
                    isShowBackButton: true,
                    isShowNext: true,
                    pageIndex: pageIndex+1,
                );
              }));
              },
          )]
        : null;
  }
}
